<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Mixin混入</title>
    <script src="https://unpkg.com/vue@next"></script>
  </head>
  <body>
    <div id="root"></div>

    <script>
      // 组件 data和methods 优先级高于mixin data和methods的优先级

      // 生命周期函数  先执行 Mixin 里面的 再执行组件里面的

    //  const Mymixin = {
    //    data() {
    //      return { number: 2 };
    //    },

    //    methods: {
    //      handleClick() {
    //        console.log("Mixin click");
    //      },
    //    },

    //    created() {
    //      console.log("Mixin created");
    //    },
    //  };

      const app = Vue.createApp({
        //data() {
        //  return {  number: 1,};
        //},

        methods: {
          handleClick() {
            console.log("handleClick");
          },
        },

        created() {
          console.log("created");
        },

        //mixins: [Mymixin],

        template: `
                      <div>{{number}}</div>
                      <div>{{count}}</div>
                      <child />
                      <button @click="handleClick">按钮</button>  
                  `,
      });

      app.mixin({
        data() {
          return { number: 2 , count: 666};
        },

        methods: {
          handleClick() {
            console.log("Mixin click");
          },
        },

        created() {
          console.log("Mixin created");
        },
      });

      app.component("child", {
        //mixins: [Mymixin],
        template: `<div>{{count}}</div>`,
      });

      const vm = app.mount("#root");
    </script>
  </body>
</html>
